package com.designoutput.ui.toolGroup
{
	import com.designoutput.enum.ToolType;
	import com.designoutput.icon.HelpIcon;
	import com.designoutput.manager.ResourceManager;
	import com.designoutput.ui.TopToolBar;
	import com.designoutput.ui.controls.BarSplit;
	import com.designoutput.ui.controls.ToolButton;
	import com.designoutput.ui.newControls.MessageBox;
	import com.designoutput.utils.Globals;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.net.navigateToURL;
	
	public class HelpGroup extends Sprite
	{
		private var topPanel:TopToolBar;
		private var help:ToolButton;
		
		internal var at:ToolButton;
		
		public function HelpGroup(topPanel:TopToolBar)
		{
			this.topPanel = topPanel;
			build();
		}
		
		private function build():void{
			var split:BarSplit = new BarSplit();
			split.x = 0;
			split.y = 5;
			this.addChild(split);
			
			help=new ToolButton(ToolType.Help, new HelpIcon(0, 0), 1, 1);
			help.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown); 
			help.addEventListener(MouseEvent.MOUSE_OVER, this.ToolMouseOver);
			help.addEventListener(MouseEvent.MOUSE_OUT, Globals.designoutputCard.hover.hideEvent);
			help.addEventListener(MouseEvent.CLICK, help_clickHandler, false, 0, true);
			help.x = 10;
			help.y = 3;
			addChild(help);
		}
		
		private function ToolMouseDown(evt:MouseEvent):void
		{
			this.at=evt.currentTarget as ToolButton;
			this.at.Mark(true);
			this.at.addEventListener(MouseEvent.MOUSE_UP, ToolMouseUp);
			
		}
		
		private function ToolMouseUp(evt:MouseEvent):void
		{
			var btn:ToolButton=evt.currentTarget as ToolButton;
			btn.Mark(false);
		} 
		private function ToolMouseOver(evt:MouseEvent):void
		{
			var type:String=(evt.currentTarget as ToolButton).type;
			switch (type)
			{
				case ToolType.Help:
					Globals.designoutputCard.hover.setText(ResourceManager.getValue("rm_help"));
					break;
				default:
					break;
			}
		}
		protected function help_clickHandler(e:MouseEvent):void {			
			var urlString:String = Globals.applicationUrl + "module.php?module=help&key=designer&popup"
			var jscommand:String = "window.open('" + urlString + "','Help','height=650,width=500,toolbar=no,scrollbars=no');";
			var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
			navigateToURL(url, "_self");
			
		}
	}
}